package com.htpb.portal.dao.hibernate;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.htpb.portal.dao.TestAccountDAO;
import com.htpb.portal.form.TestAccount;

@Repository
public class TestAccountHibernateDAO implements TestAccountDAO{
	
	@Autowired
	private SessionFactory sessionFactory;

	public void addContact(TestAccount account) {
		sessionFactory.getCurrentSession().save(account);
		
	}

	@SuppressWarnings("unchecked")
	public List<TestAccount> listContact() {
		return sessionFactory.getCurrentSession().createQuery("from TestAccount").list();
	}

	public void removeContact(Integer id) {
		TestAccount contact = (TestAccount) sessionFactory.getCurrentSession().load(
                TestAccount.class, id);
        if (null != contact) {
            sessionFactory.getCurrentSession().delete(contact);
        }
		
	}
	
	

}
